package com.ebai.product.management.controller.system;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ebai.product.management.base.controller.WebController;
import com.ebai.product.management.base.utils.Common;
import com.ebai.product.management.service.system.RoleUserService;

import net.sf.json.JSONObject;

/**
 * 角色用户管理
 * @author mgli
 *
 */
@Controller
@RequestMapping("/system/roleuser")
public class RoleUserController extends WebController{
	
	@Autowired
	private RoleUserService roleUserService;

	/**
	 * 角色用户管理主页面
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/index")
	@RequiresPermissions("system:roleuser:view")
    public String indexPage(ModelMap modelMap) {
        return "system/roleuser/index";
    }
	
	/**
	 * 保存角色用户数据-单角色多人员
	 * @param response
	 * @param rolePid
	 * @param userPids
	 */
	@RequestMapping("/saveRoleUser")
    @Transactional(rollbackFor=Exception.class)
    public void saveRoleUers(HttpServletResponse response, String rolePid, String userPids) {
        JSONObject result = Common.getJsonResult(this.roleUserService.saveRoleUsersData(rolePid, userPids));
        this.sendDirectToClient(response, CONTENTTYPE_JSON, result.toString());
    }
	
	/**
	 * 保存角色用户数据-》单人员多角色
	 * @param response
	 * @param rolePid
	 * @param userPids
	 */
	@RequestMapping("/saveUserRole")
    @Transactional(rollbackFor=Exception.class)
    public void saveUserRoles(HttpServletResponse response, String rolePids, String userPid) {
        JSONObject result = Common.getJsonResult(this.roleUserService.saveUserRolesData(rolePids, userPid));
        this.sendDirectToClient(response, CONTENTTYPE_JSON, result.toString());
    }
}
